//
//  AppDelegate+Settings.m
//  digitalCurrency
//
//  Created by apple on 2019/2/20.
//  Copyright © 2019年 XinHuoKeJi. All rights reserved.
//

#import "AppDelegate+Settings.h"
#import "IQKeyboardManager.h"
//#import "BaiduMobStat.h"//百度统计
#import "UMMobClick/MobClick.h"//友盟统计
#import "ZLAdvertView.h"
#import "UIImage+GIF.h"
#import "IOSDeviceConfig.h"

static  NSString * s_host = @"ipfsroom.cn";

@implementation AppDelegate (Settings)

-(void)initMob {
    UMConfigInstance.appKey    = @"5ccff5ff3fc195a395000442";
    UMConfigInstance.channelId = @"Adhoc";
    [MobClick startWithConfigure:UMConfigInstance];
    [MobClick setLogEnabled:YES];
}

-(void)getHost {
//    NSString *hip = [IOSDeviceConfig getIPAddressByHostName:s_host];
//    self.socket_host_ip = hip;
//    if (!hip) {
//        self.socket_host_ip = @"47.75.36.127";
//    }
//    NSLog(@"hostip:%@",self.socket_host_ip);
}

- (void)initGuaidView {
    //引导页
//    KSGuaidManager.images = @[[UIImage imageNamed:@"guid01"],
//                                  [UIImage imageNamed:@"guid02"],
//                                  [UIImage imageNamed:@"guid03"]];
//    KSGuaidManager.shouldDismissWhenDragging = YES;
//    KSGuaidManager.pageIndicatorTintColor=[UIColor whiteColor];
//    KSGuaidManager.currentPageIndicatorTintColor=baseColor;
//    [KSGuaidManager begin];
}

-(void)initKeyboardManager
{
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    keyboardManager.enable = YES;// 控制整个功能是否启用
    keyboardManager.shouldResignOnTouchOutside = YES;// 控制点击背景是否收起键盘
    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES;// 控制键盘上的工具条文字颜色是否用户自定义
    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews;// 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
    keyboardManager.enableAutoToolbar = YES;// 控制是否显示键盘上的工具条
    keyboardManager.shouldShowToolbarPlaceholder = NO;// 是否显示占位文字
    keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17]; // 设置占位文字的字体
    keyboardManager.keyboardDistanceFromTextField = 10.0f;
}

#pragma mark - 判断是不是首次登录或者版本更新
-(BOOL )isFirstLauch {
    //获取当前版本号
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *currentAppVersion = infoDic[@"CFBundleShortVersionString"];
    //获取上次启动应用保存的appVersion
    NSString *version = [[NSUserDefaults standardUserDefaults] objectForKey:@"appVersion"];
    //版本升级或首次登录
    if (version == nil || ![version isEqualToString:currentAppVersion]) {
        [[NSUserDefaults standardUserDefaults] setObject:currentAppVersion forKey:@"appVersion"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return YES;
    }
    else{
        return NO;
    }
}

//-(void)customLaunchImageView {
//
//    UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
//    launchImageView.image = [self getLaunchImage];
//    [self.window addSubview:launchImageView];
//    [self.window bringSubviewToFront:launchImageView];
//
//    //    UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kWindowH == 812.0 ? 64 : 0, 288 * kWindowWHOne, kWindowH - (kWindowH == 812.0 ? 145 : 0 ))];
//    UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 144, 422)];
//    gifImageView.center = self.window.center;
//    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"启动页.gif" ofType:nil];
//    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
//    gifImageView.image = [UIImage sd_animatedGIFWithData:imageData];
//    [launchImageView addSubview:gifImageView];
//
//    [UIView animateWithDuration:0.5f delay:5.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
//        launchImageView.alpha = 0;
//    } completion:^(BOOL finished) {
//        //         设置启动页广告
//        [self setupAdvert];
//        [launchImageView removeFromSuperview];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"launchImageViewDismiss" object:nil];
//    }];
//}

//- (UIImage *)getLaunchImage
//{
//    UIImage *lauchImage = nil;
//    NSString *viewOrientation = nil;
//    CGSize viewSize = [UIScreen mainScreen].bounds.size;
//    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
//
//    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
//
//        viewOrientation = @"Landscape";
//    }
//    else {
//        viewOrientation = @"Portrait";
//    }
//
//    NSArray *imagesDictionary = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
//    for (NSDictionary *dict in imagesDictionary) {
//
//        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
//        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
//            lauchImage = [UIImage imageNamed:dict[@"UILaunchImageName"]];
//        }
//    }
//    return lauchImage;
//}

/**
 *  判断文件是否存在
 */
- (BOOL)isFileExistWithFilePath:(NSString *)filePath {
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDirectory = FALSE;
   
    return [fileManager fileExistsAtPath:filePath isDirectory:&isDirectory];
}

@end
